<?php
/**
 * Smarty plugin
 * @category VaselinEngine
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {input} function plugin
 *
 * Type:     function<br>
 * Name:     input<br>
 * Purpose:  print out standart html input field. Used by Bel_Forms_Builder 
 * @author Konstantin Shamko <konstantin.shamko@gmail.com>
 * @param array parameters
 * @param Smarty
 * @return string|null
 */
function smarty_function_input($params,&$smarty){

	if (!isset($params['name'])){
		$smarty->trigger_error("<b>FormGenerator (input_plugin) warning:<b/> missing 'name' parameter");
		$error_flag=1;
	}

	if (!isset($params['type'])){
		$smarty->trigger_error("<b>FormGenerator (input_plugin) warning:<b/> missing 'type' parameter");
		$error_flag=1;
	}

	if($error_flag) return;

	unset($params['label']);

	switch($params['type']){
		case 'textarea':
			$value=$params['value'];
			unset($params['value']);
			$html_output='<textarea ';
			generateSharedOutput($params,$html_output);
			$html_output.='>'.(string)$value.'</textarea>';
			unset ($value);
			break;
		default:
			$html_output='<input ';
			generateSharedOutput($params,$html_output);
			$html_output.='/>';
			break;
	}

		echo $html_output;
		unset($params,$html_output);
}

function generateSharedOutput($params,&$html_output){
	foreach($params as $_key => $_val) {
		$html_output.=$_key.'="'.$_val.'" ';
	}
	
	if(!$params['id']) $html_output.="id='".$params['name']."_id' ";
}